package logic

import (
	"context"
	"github.com/pkg/errors"
	"zg2_zy/zy6_company/companyRpc/models"

	"zg2_zy/zy6_company/companyRpc/company"
	"zg2_zy/zy6_company/companyRpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateJobLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateJobLogic {
	return &UpdateJobLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateJobLogic) UpdateJob(in *company.UpdateJobRequest) (*company.UpdateJobResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	var c models.Company
	if err = c.GetJobById(); err != nil {
		return nil, errors.New("职位信息获取失败")
	}

	if c.ID == 0 {
		return nil, errors.New("该职位不存在")
	}

	c.Salary = float64(in.Salary)
	c.Degree = in.Degree
	models.DB.Updates(&c)

	return &company.UpdateJobResponse{
		Id: int64(c.ID),
	}, nil
}
